package com.todo.sight.application.backend.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.todo.common.common.entity.response.BizPageResponse;
import com.todo.common.common.entity.response.BizResponse;
import com.todo.common.common.entity.response.page.PageResult;
import com.todo.sight.application.backend.service.CityInfoBackendService;
import com.todo.sight.application.convert.CityInfoConvert;
import com.todo.sight.application.entity.bo.CityInfoBO;
import com.todo.sight.application.entity.condition.CityInfoConditionBO;
import com.todo.sight.application.iface.backend.request.*;
import com.todo.sight.application.iface.backend.response.CityInfoDetailResp;
import com.todo.sight.application.iface.backend.response.QueryCityInfoByConditionResp;
import com.todo.sight.application.service.CityInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * (CityInfo)表服务实现类
 *
 * @author zhangwenxiang
 * @since 2024-03-04 00:19:44
 */
@Slf4j
@Service("cityInfoBackendService")
public class CityInfoBackendServiceImpl implements CityInfoBackendService {

    @Resource
    private CityInfoService cityInfoService;

    @Override
    public BizResponse<Boolean> insertCityInfo(InsertCityInfoReq req) {
        if (req == null || !req.baseCheck()) {
            return BizResponse.paramError("参数异常");
        }
        CityInfoBO cityInfoBO = CityInfoConvert.insertCityInfoReqconverToCityInfoBO(req);
        Boolean insertResult = cityInfoService.insertCityInfo(cityInfoBO);
        return BizResponse.success(insertResult);
    }

    @Override
    public BizResponse<Boolean> updateCityInfoById(UpdateCityInfoReq req) {
        if (req == null || !req.baseCheck()) {
            return BizResponse.paramError("参数异常");
        }
        CityInfoBO cityInfoBO = CityInfoConvert.updateCityInfoReqconverToCityInfoBO(req);
        Boolean updateResult = cityInfoService.updateCityInfo(cityInfoBO);
        return BizResponse.success(updateResult);
    }

    @Override
    public BizResponse<Boolean> removeCityInfoById(RemoveCityInfoByIdReq req) {
        if (req == null || !req.baseCheck()) {
            return BizResponse.paramError("参数异常");
        }
        Boolean removeResult = cityInfoService.removeCityInfoById(req.getId());
        return BizResponse.success(removeResult);
    }

    @Override
    public BizResponse<Boolean> enableCityInfoById(EnableCityInfoByIdReq req) {
        if (req == null || !req.baseCheck()) {
            return BizResponse.paramError("参数异常");
        }
        Boolean enableResult = cityInfoService.enableCityInfoById(req.getId(), req.getIsShow());
        return BizResponse.success(enableResult);
    }

    @Override
    public BizResponse<CityInfoDetailResp> queryCityInfoById(QueryCityInfoByIdReq req) {
        if (req == null || !req.baseCheck()) {
            return BizResponse.paramError("参数异常");
        }
        CityInfoBO cityInfoBO = cityInfoService.queryCityInfoById(req.getId());
        return BizResponse.success(CityInfoConvert.convertToCityInfoDetailResp(cityInfoBO));
    }

    @Override
    public BizPageResponse<QueryCityInfoByConditionResp> queryCityInfoByCondition(QueryCityInfoByConditionReq req) {
        if (req == null || !req.baseCheck()) {
            return BizPageResponse.paramError("参数异常");
        }
        CityInfoConditionBO cityInfoConditionBO = CityInfoConvert.convertToCityInfoConditionBO(req);
        PageResult<CityInfoBO> result = cityInfoService.queryCityInfoByCondition(cityInfoConditionBO);
        if (result == null || CollectionUtils.isEmpty(result.getResults())) {
            log.info("CityInfoBackendService#queryCityInfoByCondition 多条件查询数据为空 入参：【{}】", JSONObject.toJSONString(req));
            return BizPageResponse.success();
        }
        return BizPageResponse.success(CityInfoConvert.convertToQueryCityInfoByConditionRespList(result));
    }

    @Override
    public BizResponse<Long> batchInsertByExcel(MultipartFile file) {
        // TODO excel相关基础功能待完善后实现
        return null;
    }
}
